php escape special characters

174

determine special characters in php -

<?php

$string = 'foo';

if (preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $string))
{
    // one or more of the 'special characters' found in $string
}

php escape special characters -

/*  EXAMPLE:	<p>Bed & Breakfast</p>	-->	  <p>Bed & Breakfast</p>  
    & 	&
    " 	" 				(unless ENT_NOQUOTES is set)
    ' 	' or ' 	(ENT_QUOTES must be set)
    < 	<
    > 	>				*/

<?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; 					// <a href='test'>Test</a>
?>

Comments

Submit
0 Comments